/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * LinearizerEditor.java
 *
 * Created on 2009-10-26, 17:45:54
 */
package mr.go.sgfilter.vis.app;

import java.awt.Color;
import java.awt.Dimension;
import javax.swing.BorderFactory;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JLabel;
import javax.swing.JSpinner;
import javax.swing.JSpinner.NumberEditor;
import javax.swing.SpinnerNumberModel;
import javax.swing.border.LineBorder;
import org.jdesktop.application.Application;
import org.jdesktop.application.ResourceMap;
import org.jdesktop.beansbinding.AutoBinding.UpdateStrategy;
import org.jdesktop.beansbinding.BeanProperty;
import org.jdesktop.beansbinding.Binding;
import org.jdesktop.beansbinding.BindingGroup;
import org.jdesktop.beansbinding.Bindings;
import org.jdesktop.beansbinding.ELProperty;

/**
 *
 * @author Rzeźnik
 */
public class LinearizerEditor extends javax.swing.JPanel {

    private final LinearizerBean bean;

    /** Creates new form LinearizerEditor */
    public LinearizerEditor() {
        this(null);
    }

    public LinearizerEditor(LinearizerBean bean) {
        this.bean = bean;
        initComponents();
    }

    public LinearizerBean getBean() {
        return bean;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        bindingGroup = new BindingGroup();
        JLabel truncateRatioLabel = new JLabel();
        truncateRatioSpinner = new JSpinner();
        ResourceMap resourceMap =
                Application.getInstance(mr.go.sgfilter.vis.app.Application.class).
                getContext().getResourceMap(LinearizerEditor.class);
        setBorder(BorderFactory.createTitledBorder(new LineBorder(new Color(0, 0, 0), 1, true), resourceMap.getString("LinearizerEditor.border.title"))); // NOI18N
        setName("LinearizerEditor"); // NOI18N
        setPreferredSize(new Dimension(470, 100));

        truncateRatioLabel.setLabelFor(truncateRatioSpinner);
        truncateRatioLabel.setText(resourceMap.getString("truncateRatioLabel.text")); // NOI18N
        truncateRatioLabel.setName("truncateRatioLabel"); // NOI18N

        truncateRatioSpinner.setModel(new SpinnerNumberModel(Float.valueOf(0.0f), Float.valueOf(0.0f), Float.valueOf(1.0f), Float.valueOf(0.05f)));
        truncateRatioSpinner.setEditor(new NumberEditor(truncateRatioSpinner, "0.##"));
        truncateRatioSpinner.setName("truncateRatioSpinner"); // NOI18N

        Binding binding = Bindings.createAutoBinding(UpdateStrategy.READ_WRITE, this, ELProperty.create("${bean.truncateRatio}"), truncateRatioSpinner, BeanProperty.create("value"));
        bindingGroup.addBinding(binding);

        GroupLayout layout = new GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(truncateRatioLabel)
                .addGap(18, 18, 18)
                .addComponent(truncateRatioSpinner, GroupLayout.PREFERRED_SIZE, 53, GroupLayout.PREFERRED_SIZE)
                .addContainerGap(279, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(Alignment.BASELINE)
                    .addComponent(truncateRatioLabel)
                    .addComponent(truncateRatioSpinner, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                .addContainerGap(45, Short.MAX_VALUE))
        );

        bindingGroup.bind();
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private JSpinner truncateRatioSpinner;
    private BindingGroup bindingGroup;
    // End of variables declaration//GEN-END:variables
}
